package HighConcurrency.Lock;

import HighConcurrency.Lock.Data1;

import javax.xml.crypto.Data;
import java.util.Date;
import java.util.concurrent.CountDownLatch;

public class VolatileDemo2 {
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch cdl = new CountDownLatch(2);
        Data1 d = new Data1();

        new Thread(new add1(d, cdl)).start();
        new Thread(new add1(d, cdl)).start();

        cdl.await();// 等待所有线程结束
        System.out.println(d.i);



    }
}
class add1 implements Runnable {
    private Data1 d;
    private CountDownLatch cdl;// 用于等待所有线程结束

    public add1(Data1 d, CountDownLatch cdl) {
        this.d = d;
        this.cdl = cdl;
    }

    public void run()
    {
        for (int i = 0; i < 1000; i++)
        {
            d.i++;
        }
    }
}